package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Attendance;
import cn.wolfcode.crm.domain.Department;
import cn.wolfcode.crm.mapper.AttendanceMapper;
import cn.wolfcode.crm.query.AttendanceQueryObject;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IAttendanceService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
public class AttendanceServiceImpl implements IAttendanceService {


    @Autowired
    AttendanceMapper attendanceMapper;

    public int deleteByPrimaryKey(Long id) {
        return attendanceMapper.deleteByPrimaryKey(id);
    }

    public int insert(Attendance record) {
        return attendanceMapper.insert(record);
    }

    public Attendance selectByPrimaryKey(Long id) {
        return attendanceMapper.selectByPrimaryKey(id);
    }

    public List<Attendance> selectAll() {
        return attendanceMapper.selectAll();
    }

    public int updateByPrimaryKey(Attendance record) {
        return attendanceMapper.updateByPrimaryKey(record);
    }

    public PageResult query(AttendanceQueryObject qo) {
        int count = attendanceMapper.queryCount(qo);
        if (count == 0) {
            return new PageResult(0, Collections.emptyList());
        }
        List<Attendance> attendances = attendanceMapper.queryList(qo);
        return new PageResult(count, attendances);
    }

    public int updateTime(String timeOut, Boolean state, Long id) {
        return attendanceMapper.updateTime(timeOut, state, id);
    }

    public Long selectIdByName(String employeeName) {
        return attendanceMapper.selectIdByName(employeeName);
    }

    public Attendance selectByUsername(String username) {
        return attendanceMapper.selectByUsername(username);
    }

    public void destroy() {
        attendanceMapper.destroy();
    }

}
